home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / print / gs261sr1.zip / GP_SYSV.C < prev    next >
C/C++ Source or Header  |  1993-05-12  |  2KB  |  69 lines

  1. /* Copyright (C) 1992 Aladdin Enterprises.  All rights reserved.
  2.  
  3. This file is part of Ghostscript.
  4.  
  5. Ghostscript is distributed in the hope that it will be useful, but
  6. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  7. to anyone for the consequences of using it or for whether it serves any
  8. particular purpose or works at all, unless he says so in writing.  Refer
  9. to the Ghostscript General Public License for full details.
  10.  
  11. Everyone is granted permission to copy, modify and redistribute
  12. Ghostscript, but only under the conditions described in the Ghostscript
  13. General Public License.  A copy of this license is supposed to have been
  14. given to you along with Ghostscript so you can know your rights and
  15. responsibilities.  It should be in a file named COPYING.  Among other
  16. things, the copyright notice and this notice must be preserved on all
  17. copies.  */
  18.  
  19. /* gp_sysv.c */
  20. /* System V Unix-specific routines for Ghostscript */
  21.  
  22. /* This file contains a couple of standard Unix library procedures */
  23. /* that a few System V platforms don't provide. */
  24. #include <errno.h>
  25. #include "time_.h"
  26. #include <sys/types.h>
  27. #include <sys/times.h>
  28. #include <sys/stat.h>
  29. #include <sys/param.h>
  30.  
  31. extern long timezone;        /* doesn't seem to be declared anywhere */
  32.  
  33. /* rename */
  34. int
  35. rename(char *a, char *b)
  36. {    if  (access(a, 0) == -1 )
  37.         return(-1);
  38.     unlink(b);
  39.     if ( link(a, b) == -1 )
  40.         return(-1);
  41.     if ( unlink(a) == -1 )
  42.     {    unlink(b);        /* ??? */
  43.         return(-1);
  44.     }
  45.     return(0);
  46. }
  47.  
  48. /* gettimeofday */
  49. #ifndef HZ
  50. #  define    HZ    100        /* see sys/param.h */
  51. #endif
  52. int
  53. gettimeofday(struct timeval *tvp, struct timezone *tzp)
  54. {    struct tms tms;
  55.     static long offset = 0;
  56.     long ticks;
  57.  
  58.     if (!offset)
  59.     {    time(&offset);
  60.         /* call localtime to set the timezone variable */
  61.         localtime(&offset);
  62.         offset -= (times(&tms) / HZ);
  63.     }
  64.     ticks = times(&tms);
  65.     tvp->tv_sec = ticks/HZ + offset;
  66.     tvp->tv_usec = (ticks % HZ) * (1000*1000/HZ);
  67.     tzp->tz_minuteswest = timezone/60;
  68. }
  69.